package nc.tb.ctl;

import java.util.HashMap;
import java.util.Iterator;

import nc.tb.bccsaction.BcCsAction;
import nc.tb.pub.NtbEnv;
import nc.tb.pub.cache.NtbCacheManager;
import nc.tb.pub.data.INtbCache;

public class ConsolidateReccCTL implements INtbCache{
	private final static String CACHE_KEY = "ConsolidateReccCTL";
	private HashMap<String,BcCsAction> hm_pk2bcs;
	public void clearCache() {
		hm_pk2bcs.clear();
		aConsolidateReccCTL = null;
	}
	private ConsolidateReccCTL() {
		hm_pk2bcs = new HashMap<String,BcCsAction>();
	}
	private static ConsolidateReccCTL aConsolidateReccCTL = null;
	public static ConsolidateReccCTL getInstance() {
		if (NtbEnv.isUICall) {
			if(aConsolidateReccCTL == null) {
				aConsolidateReccCTL = new ConsolidateReccCTL();
				NtbCacheManager.putCacheInstance(CACHE_KEY, aConsolidateReccCTL);
			}
			return aConsolidateReccCTL;
		}
		ConsolidateReccCTL inst = (ConsolidateReccCTL) NtbCacheManager.getCacheInstance(CACHE_KEY);
		if(inst == null) {
			inst = new ConsolidateReccCTL();
			NtbCacheManager.putCacheInstance(CACHE_KEY, inst);
		}
		return inst;
	}
	public void removePk(String pk) {
		hm_pk2bcs.remove(pk);
	}
	public BcCsAction getPk(String pk) {
		return hm_pk2bcs.get(pk);
	}
	public void putValue(String pk, BcCsAction bs) {
		hm_pk2bcs.put(pk, bs);
	}
	public BcCsAction[] getAllEntrys() {
		BcCsAction[] result = hm_pk2bcs == null ? new BcCsAction[0] : new BcCsAction[hm_pk2bcs.size()];
		Iterator<BcCsAction> it = hm_pk2bcs.values().iterator();
		int idx = 0;
		while (it.hasNext()) {
			result[idx] = it.next();
			idx++;
		}
		return result;
	}
}
